package com.operate.api.app.dramas.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.github.pagehelper.PageInfo;
import com.operate.api.app.dramas.domain.vo.*;
import com.operate.api.base.ApiIndex;
import com.operate.api.base.IDEntity;
import com.operate.api.base.R;
import com.operate.api.base.RestPage;
import com.operate.api.operate.dramas.service.IDramasService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


@Api( tags = ApiIndex.AppDramasController)
@RequestMapping(value = "/api/app/dramas")
@RestController
public class AppDramasController {

    @Autowired
    private IDramasService service;

    @ApiOperation(value = "查询片花列表【精选页面】")
    @GetMapping(value = "/trailers_list")
    public R<RestPage<List<DramaTrailersVO>>> trailers_list(
            @ApiParam(value = "查询参数") @ModelAttribute DramaTrailersSearchVO searchVO) {
        List<DramaTrailersVO> list = service.getTrailersList(searchVO);
        RestPage restPage = new RestPage(new PageInfo(list), list);
        return new R(restPage);
    }


    @ApiOperation(value = "查询剧目详情【片花详情】")
    @GetMapping(value = "/trailers_desc")
    public R<DramaTrailersVO> trailers_desc(
            @ApiParam(value = "查询参数") @ModelAttribute IDEntity searchVO) {
        DramaTrailersVO dramaTrailersVO = service.getTrailersDesc(searchVO.getId());
        return new R(dramaTrailersVO);
    }


    @ApiOperation(value = "查询剧目列表【商户内容】")
    @GetMapping(value = "/company_dramas")
    public R<RestPage<List<DramaCompanyVO>>> company_dramas(
            @ApiParam(value = "查询参数") @ModelAttribute DramaCompanySearchVO searchVO) {
        List<DramaCompanyVO> list = service.getCompanyDramas(searchVO);
        RestPage restPage = new RestPage(new PageInfo(list), list);
        return new R(restPage);
    }



    @ApiOperation(value = "检查剧目是否收藏(追剧)")
    @PostMapping(value = "/check_collect")
    @SaCheckLogin
    public R<Boolean> check_collect(@ApiParam(value = "参数")  @RequestBody AppCollectVO vo) {
        Boolean r=service.checkCollect(vo);
        return new R(r);
    }

    @ApiOperation(value = "剧目取消收藏(追剧)[需要登录]")
    @PostMapping(value = "/cancel_collect")
    @SaCheckLogin
    public R cancel_collect(@ApiParam(value = "参数")  @RequestBody AppCollectVO vo) {
        service.cancelCollect(vo);
        return new R();
    }


    @ApiOperation(value = "查询我追剧列表[需要登录]")
    @GetMapping(value = "/collect_list")
    public R<RestPage<List<DramaCompanyVO>>> collectList(
            @ApiParam(value = "查询参数") @ModelAttribute DramaCollectSearchVO searchVO) {
        List<DramaCompanyVO> list = service.getCollectList(searchVO);
        RestPage restPage = new RestPage(new PageInfo(list), list);
        return new R(restPage);
    }


    @ApiOperation(value = "查询剧目追剧数量")
    @GetMapping(value = "/dramas_collect_num")
    public R<Integer> dramas_collect_num(@ApiParam(value = "剧目ID") @ModelAttribute IDEntity idEntity) {
        return new R(service.geDramasCollectNum(idEntity.getId()));
    }

    @ApiOperation(value = "查询我追剧数量[需要登录]")
    @GetMapping(value = "/collect_num")
    @SaCheckLogin
    public R<Integer> collect_num() {
        return new R(service.getCollectNum());
    }

    @ApiOperation(value = "剧目收藏(追剧)[需要登录]")
    @PostMapping(value = "/add_collect")
    @SaCheckLogin
    public R drams_collect(@ApiParam(value = "参数")  @RequestBody AppCollectVO vo) {
        service.addCollect(vo);
        return new R();
    }


    @ApiOperation(value = "片花播放")
    @PostMapping(value = "/play_drama")
    public R play_drama(@ApiParam(value = "参数")  @RequestBody AppDramasPlayVO vo) {
        service.playDrama(vo);
        return new R();
    }




}